<?php
include_once("_common.php");
include_once("$mw_cash[path]/cybercash.lib.php");

if (get_session("cash_membership") && $bo_table)
    $g4[title] = "$board[bo_subject] 멤버쉽 결제";
else
    $g4[title] = "$mw_cash[cf_cash_name] 충전";

include_once("$g4[path]/head.sub.php");

if (!$is_member)
    alert_close("로그인 후 이용해주세요.");

$sql = "select * from $mw_cash[cash_list_table] where mb_id = '$member[mb_id]' and cl_id = '$cl_id' ";
$cash_list = sql_fetch($sql);

if (!$cash_list)
    alert_close("신청내역이 존재하지 않습니다.");

if ($cash_list[cl_status])
    alert_close("이미 충전이 완료되었습니다.");

switch ($cash_list[cl_paytype]) {
    case "신용카드" : $paytype = 1; break;
    case "계좌이체" : $paytype = 2; break;
    case "핸드폰" : $paytype = 3; break;
    //case "가상계좌" : $paytype = 4; break;
    case "페이팔": $paytype = 5; break;
}

if ($paytype == '5' && $mw_cash[cf_paypal_foreign] && mw_cash_is_korea() && !$is_admin) {
    alert_close("해외에서만 페이팔 결제가 가능합니다.");
}

$is_paypal = false;
if ($mw_cash[cf_paypal] && $paytype == '5') {
    $is_paypal = true;
    $mw_cash[cf_pg] = 'paypal';
}

// 결제상품명
$pay_name = $mw_cash[cf_cash_name];

$cash_contents = get_session("cash_contents");
$cash_membership = get_session("cash_membership");

if ($cash_contents) {
    $tmp = explode("@", $cash_contents);
    $bo_table = $tmp[0];
    $wr_id = $tmp[1];

    $tmp = sql_fetch("select wr_subject from {$g4['write_prefix']}{$bo_table} where wr_id = '{$wr_id}'");
    if (!$tmp)
        alert("컨텐츠가 존재하지 않습니다.");

    $pay_name = strip_tags($tmp['wr_subject']);
}
else if ($cash_membership)
{
    $cash_membership_count = 0;

    if (is_array($cash_membership)) {
        $cash_membership_count = count($cash_membership) - 1;
        $tmp = sql_fetch(" select * from $mw_cash[membership_item_table] where mi_id = '{$cash_membership[0]}' ");
        $ms_id = $tmp[ms_id];
    }
    else {
        $tmp = explode("@", $cash_membership);
        $ms_id = $tmp[0];
    }

    $sql = "select * from $mw_cash[membership_table] where ms_id = '$ms_id' ";
    $tmp = sql_fetch($sql);
    if (!$tmp)
        alert("멤버쉽[$ms_id] 이 존재하지 않습니다.");

    $pay_name = strip_tags($tmp['ms_name']);
    if ($cash_membership_count)
        $pay_name .= "외 {$cash_membership_count}개";
}
?>

<style type="text/css">
body { padding:10px; }
h3 { font-size:15px; }
.account-info { border:5px solid #efefef; padding:20px; font-weight:bold; text-align:center; font-size:13px; }
td.head { border-bottom:1px solid #ddd; padding:10px; font-weight:bold; }
td.body { border-bottom:1px solid #ddd; padding:10px; }
.btn1 { background-color:#efefef; cursor:pointer; }
.hints { color:#888; margin:5px 0 5px 0; }
#payment-info { color:#888; }
</style>

<h3> <img src="img/icon_cash.gif" align="absmiddle"> <?=$g4[title]?> </h3>

<div class="account-info"> <?=$cash_list[cl_paytype]?> 결제  </div>

<table border="0" cellpadding="0" cellspacing="0" align="center" style="margin:0 auto 0 auto;">
<colgroup width="150"/>
<colgroup width="300"/>

<? if (!get_session("cash_membership")) { ?>
<tr>
    <td class="head"> <?=$mw_cash[cf_cash_name]?> 충전 </td>
    <td class="body">
	<?=number_format($cash_list[cl_cash])?> <?=$mw_cash[cf_cash_unit]?>
    </td>
</tr>
<? } ?>
<tr>
    <td class="head"> 결제금액 </td>
    <td class="body">
        <? if ($is_paypal) { ?>
	<?=number_format($cash_list[cl_payment], 2)?> $ 
        <? } else { ?>
	<?=number_format($cash_list[cl_payment])?> 원
        <? } ?>
    </td>
</tr>

<? /*if ($paytype == "2" && !get_session("pid")) { ?>
<tr>
    <td class="head"> 주민등록번호 </td>
    <td class="body">
        <form name="tmp_pid">
	<input type="text" size="20" maxlength="13" minlength="13" name="pid" required itemname="주민등록번호" class="ed" onblur="mainForm.pid.value=this.value">
	<div class="hints">'-' 기호 없이 숫자만 입력해주세요.</div>
	<div class="hints">계좌이체는 주민등록번호를 필요로 합니다.</div>
	<div class="hints">본인확인 절차로만 사용되며 DB에 저장하지 않습니다.</div>
        </form>
    </td>
</tr>
<? }*/ ?>
</table>

<? if ($mw_cash[cf_happybean]) { ?>
<div style="margin:10px 0 0 10px; color:#999;">
결제하신 금액의 <?=$mw_cash[cf_happybean]?>% 를 어려운 이웃을 돕는 해피빈에 기부합니다.
(<?=number_format(mw_cash_to_payment($cash_list[cl_cash], 0)*$mw_cash[cf_happybean]/100)?> 원)
</div>
<? } ?>

<? include_once("pg.{$mw_cash[cf_pg]}.inc.php") ?>


<div style="color:red; text-align:center; margin:10px 0;">결제가 완료될 때 까지 창을 닫지 마세요.</div>

<div id="payment-button" style="margin:30px 0 30px 0; text-align:center;">
<input type="button" value="결제하기" class="btn1" onclick="openWindow()">
</div>




<?
include_once("$g4[path]/tail.sub.php");
